<template>
  <div>
    <el-row style="margin-bottom:10px">
      <el-col :span="8" >
        <h4 style="margin:0">
          <span>认证审核</span>
        </h4>
      </el-col>
      <el-col :span="16" style="text-align:right">
        
      </el-col>
    </el-row>
   
    <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55"></el-table-column>-->
      <el-table-column prop="ID" label="序号" width="60">
         <template slot-scope="scope">{{scope.$index+1}}</template>
      </el-table-column>
      <el-table-column prop="city" label="提交时间">
         <template slot-scope="scope">
          {{timeFun(scope.row.created_at)}}
        </template>
      </el-table-column>   
      <el-table-column prop="hospital_name" label="机构名称"></el-table-column>

      <el-table-column prop="account_name" label="账号"></el-table-column>
      <el-table-column prop="front" label="营业执照">
         <template slot-scope="scope">
           <img :src="scope.row.front" @click="showImage(scope.row.front)" style="width:70px;height:80px"/>
        </template>
      </el-table-column>
      <el-table-column prop="doctor_count" label="医疗许可">
        <template slot-scope="scope">
           <img :src="scope.row.behind" @click="showImage(scope.row.behind)" style="width:70px;height:80px"/>
        </template>
      </el-table-column>
      <el-table-column prop="tui" label="状态">
        <template  slot-scope="scope">
          <span style="color:#67c23a" v-if="scope.row.status==1">通过</span>
          <span style="color:red" v-else-if="scope.row.status==2">审核未通过</span>
          <span v-else>待审核</span>
        </template>
      </el-table-column>

      <el-table-column width="150" label="操作">
        <template slot-scope="scope">
          <div v-if="userRole.HPT_CERT_1703001">
            <el-button class="addBtn" v-if="scope.row.status==1" type="warning" @click="unPasssFun(scope.row.hospital_id)">取消通过</el-button>
            <el-button class="addBtn" v-if="scope.row.status != 1" type="success" @click="passsFun(scope.row.hospital_id)">通过</el-button>
            <el-button class="addBtn" type="primary" @click="addInfo(scope.row.hospital_id)">反馈</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :visible.sync="showSta">
      <img width="100%" :src="showImgeUrl" alt="">
    </el-dialog>

    <el-dialog title="反馈内容" :visible.sync="dialogVisible" width="40%">
      <div>
        <el-input type="textarea" :rows="3" placeholder="请输入反馈内容" v-model="result_msg"> </el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addSpeakFun(0)">确 定</el-button>
      </span>
    </el-dialog>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        dialogVisible:false,
        dataPush:'',
        total:0,
        showSta:false,
        showImgeUrl:'',
        result_msg:'',
        currentPage4: 1,//分野  
        page:1,
        pageSize:10,
        tableData: []
      }
    },
    created(){
      this.getlist()
    },
    methods: {
      getlist(){
        Http.getCertListlist({
          "pageIndex":this.page,
          "pageSize":this.pageSize
        })
        .then( res => {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total;
           this.pushStatus = false
        })
        .catch( error => {
          
        })
      },
      getdata (evt) {
      },
      
      showImage(row){
        this.showSta = true;
        this.showImgeUrl = row
      },
      timeFun(val) {
        return getTime(val)
      },
      addInfo(row){
        this.id = row;
        this.dialogVisible = true;
      },
      passsFun(row) {
        const obj = {
          "status":1,
          "hospital_id":row,
        };
        this.ajaxFun(obj)
      },
      unPasssFun(row) {
        const obj = {
          "status":2,
          "hospital_id":row,
        };
        this.ajaxFun(obj)
      },
      addSpeakFun() {
        if(!this.result_msg){
          this.$message.error('请输入反馈内容');
          return
        }
        const obj = {
          "status":2,
          "hospital_id":this.id,
          "result_msg":this.result_msg
        };
        this.ajaxFun(obj)
      },
      ajaxFun(obj) {
         Http.auditCert(obj)
        .then( res => {
          if (res.data.code == 200) {
            this.$message.success('审核成功')
            this.dialogVisible = false;
            this.getlist()
          } else {
            this.$message.error(`审核失败原因：${res.data.message}`)
          }
        })
        .catch(_ => {
          this.$message.error('服务器请求失败')
        });
      },
      //选择 推荐
      handleSelectionChange() {
        
      },
         //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getlist()
        
      },
    }
  }
</script>
<style  scoped>
.box{
  border-bottom:1px solid red;
}
    .test{
        border:1px solid #ccc;
    }
    .drag-item{
        width: 200px;
        height: 50px;
        line-height: 50px;
        margin: auto;
        position: relative;
        
        background: #ddd;
        margin:20px 5px;
    }
    .ghostClass{
        opacity: 1;
    }
    .bottom{
        width: 200px;
        height: 50px;
        position: relative;
        background: blue;
        top:2px;
        left: 2px;
        transition: all .5s linear;
    }
</style>
